import time

class TickerClock:
    """毫秒定时器"""
    def __init__(self, diff = 100):
        self.__deadline = None
        self.__ticks = time.ticks_ms()
        self.__diff = int(diff)
        self.reset()

    def reset(self):
        self.__ticks = time.ticks_ms()
        self.__deadline = time.ticks_add(self.__ticks, self.__diff)

    def get_diff(self):
        cur_tick = time.ticks_ms()
        diff = cur_tick - self.__ticks
        return diff

    def check(self):
        cur_tick = time.ticks_ms()
        if time.ticks_diff(self.__deadline, cur_tick):
            self.reset()
            return True
        return False
